package com.mjkj.controller;

import com.mjkj.core.result.Result;
import com.mjkj.core.result.ResultGenerator;
import com.mjkj.service.TPayService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 支付交易表 前端控制器
 * </p>
 *
 * @author shironeko
 * @since 2025-01-06
 */
@Tag(name = "支付交易表")
@RestController
@Slf4j
public class TPayController {

    @Resource
    private TPayService tPayService;

    @GetMapping("/t-pay/list")
    @Operation(summary = "支付交易表列表")
    public Result list(){
        return ResultGenerator.genSuccessResult(tPayService.list());
    }

    @GetMapping("/t-pay/get/{id}")
    @Operation(summary = "根据id获取交易信息")
    public Result get(@PathVariable(value = "id") Long id){
        if(Long.valueOf(-1).equals(id)){
            throw new RuntimeException("id不能为-1");
        }
        if(Long.valueOf(-2).equals(id)){
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return ResultGenerator.genSuccessResult(tPayService.getById(id));
    }
}
